<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: pico_rand</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.0.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__pico__rand.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">pico_rand<div class="ingroups"><a class="el" href="group__high__level.html">High Level APIs</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Random Number Generator API.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga97a9544b527a3ba865ab70142bdd5d1b"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__rand.html#ga97a9544b527a3ba865ab70142bdd5d1b">get_rand_128</a> (<a class="el" href="structrng__128.html">rng_128_t</a> *rand128)</td></tr>
<tr class="memdesc:ga97a9544b527a3ba865ab70142bdd5d1b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 128-bit random number.  <a href="group__pico__rand.html#ga97a9544b527a3ba865ab70142bdd5d1b">More...</a><br /></td></tr>
<tr class="separator:ga97a9544b527a3ba865ab70142bdd5d1b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga783185fba81c03eb0c1d687d322b0112"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__rand.html#ga783185fba81c03eb0c1d687d322b0112">get_rand_64</a> (void)</td></tr>
<tr class="memdesc:ga783185fba81c03eb0c1d687d322b0112"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 64-bit random number.  <a href="group__pico__rand.html#ga783185fba81c03eb0c1d687d322b0112">More...</a><br /></td></tr>
<tr class="separator:ga783185fba81c03eb0c1d687d322b0112"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac446d739bd6818ee25b5c8644ef7c8e8"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__rand.html#gac446d739bd6818ee25b5c8644ef7c8e8">get_rand_32</a> (void)</td></tr>
<tr class="memdesc:gac446d739bd6818ee25b5c8644ef7c8e8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 32-bit random number.  <a href="group__pico__rand.html#gac446d739bd6818ee25b5c8644ef7c8e8">More...</a><br /></td></tr>
<tr class="separator:gac446d739bd6818ee25b5c8644ef7c8e8"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p >Random Number Generator API. </p>
<p >This module generates random numbers at runtime utilizing a number of possible entropy sources and uses those sources to modify the state of a 128-bit 'Pseudo Random Number Generator' implemented in software.</p>
<p >The random numbers (32 to 128 bit) to be supplied are read from the PRNG which is used to help provide a large number space.</p>
<p >The following (multiple) sources of entropy are available (of varying quality), each enabled by a #define:</p>
<ul>
<li>The Ring Oscillator (ROSC) (PICO_RAND_ENTROPY_SRC_ROSC == 1): PICO_RAND_ROSC_BIT_SAMPLE_COUNT bits are gathered from the ring oscillator "random bit" and mixed in each time. This should not be used if the ROSC is off, or the processor is running from the ROSC. <dl class="section note"><dt>Note</dt><dd>the maximum throughput of ROSC bit sampling is controlled by PICO_RAND_MIN_ROSC_BIT_SAMPLE_TIME_US which defaults to 10us, i.e. 100,000 bits per second.</dd></dl>
</li>
<li>Time (PICO_RAND_ENTROPY_SRC_TIME == 1): The 64-bit microsecond timer is mixed in each time.</li>
<li>Bus Performance Counter (PICO_RAND_ENTROPY_SRC_BUS_PERF_COUNTER == 1): One of the bus fabric's performance counters is mixed in each time.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>All entropy sources are hashed before application to the PRNG state machine.</dd></dl>
<p>The <em>first</em> time a random number is requested, the 128-bit PRNG state must be seeded. Multiple entropy sources are also available for the seeding operation:</p>
<ul>
<li>The Ring Oscillator (ROSC) (PICO_RAND_SEED_ENTROPY_SRC_ROSC == 1): 64 bits are gathered from the ring oscillator "random bit" and mixed into the seed.</li>
<li>Time (PICO_RAND_SEED_ENTROPY_SRC_TIME == 1): The 64-bit microsecond timer is mixed into the seed.</li>
<li>Board Identifier (PICO_RAND_SEED_ENTROPY_SRC_BOARD_ID == 1): The board id via <a class="el" href="group__pico__unique__id.html#gaf87ef8a55d8dc2520776e427a605b6fb">pico_get_unique_board_id</a> is mixed into the seed.</li>
<li>RAM hash (PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH (PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH): The hashed contents of a subset of RAM are mixed in. Initial RAM contents are undefined on power up, so provide a reasonable source of entropy. By default the last 1K of RAM (which usually contains the core 0 stack) is hashed, which may also provide for differences after each warm reset.</li>
</ul>
<p >With default settings, the seed generation takes approximately 1 millisecond while subsequent random numbers generally take between 10 and 20 microseconds to generate.</p>
<p >pico_rand methods may be safely called from either core or from an IRQ, but be careful in the latter case as the calls may block for a number of microseconds waiting on more entropy. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga97a9544b527a3ba865ab70142bdd5d1b" name="ga97a9544b527a3ba865ab70142bdd5d1b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga97a9544b527a3ba865ab70142bdd5d1b">&#9670;&nbsp;</a></span>get_rand_128()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void get_rand_128 </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structrng__128.html">rng_128_t</a> *&#160;</td>
          <td class="paramname"><em>rand128</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 128-bit random number. </p>
<p >This method may be safely called from either core or from an IRQ, but be careful in the latter case as the call may block for a number of microseconds waiting on more entropy.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">rand128</td><td>Pointer to storage to accept a 128-bit random number </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gac446d739bd6818ee25b5c8644ef7c8e8" name="gac446d739bd6818ee25b5c8644ef7c8e8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac446d739bd6818ee25b5c8644ef7c8e8">&#9670;&nbsp;</a></span>get_rand_32()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t get_rand_32 </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 32-bit random number. </p>
<p >This method may be safely called from either core or from an IRQ, but be careful in the latter case as the call may block for a number of microseconds waiting on more entropy.</p>
<dl class="section return"><dt>Returns</dt><dd>32-bit random number </dd></dl>

</div>
</div>
<a id="ga783185fba81c03eb0c1d687d322b0112" name="ga783185fba81c03eb0c1d687d322b0112"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga783185fba81c03eb0c1d687d322b0112">&#9670;&nbsp;</a></span>get_rand_64()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint64_t get_rand_64 </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 64-bit random number. </p>
<p >This method may be safely called from either core or from an IRQ, but be careful in the latter case as the call may block for a number of microseconds waiting on more entropy.</p>
<dl class="section return"><dt>Returns</dt><dd>64-bit random number </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>